package com.goldcn.order.controller;

import com.goldcn.common.ExportExcel;
import com.goldcn.common.util.CommonUtils;
import com.goldcn.config.ProConstants;
import com.goldcn.order.service.OrderService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:导出报表控制器
 * @Author Tim Peng
 * @date 2017-5-19 15:49:35
 * @version V1.0
 */
@RestController
@RequestMapping("/export")
@Api(value = "导出", description = "导出报表")
public class ExportController {
    @Autowired
    OrderService orderService;

    @RequestMapping(value = "/excel",method = RequestMethod.POST)
    public void exportExcel(HttpServletRequest request, HttpServletResponse response) throws Exception{
        String excelName = ProConstants.EXPORT_ORDER_DETAIL + "_"+ CommonUtils.getCurTimestamp();
        response.setCharacterEncoding("UTF-8");
        List<Map<String, String>> list = new ArrayList<>();
        //Map<String,String> map = CommonTools.getParameterMap(request, false);
        Map<String,String> map = new HashMap<>();
        map.put("code","EXPORTORDERDETAIL");
        map.put("columns","[{'header':'商户订单号','field':'orderNO'},{'header':'支付订单号','field':'payNo'},{'header':'商品款号','field':'prdNo'},{'header':'下单时间','field':'addTime'},{'header':'支付时间','field':'payTime'},{'header':'下单人姓名','field':'userName'},{'header':'产品名称','field':'goodName'}]");
        switch (map.get("code")){
            case ProConstants.EXPORT_ORDER_DETAIL:
                list=orderService.exportOrderDetail(map,request,response);
                break;
        }
        ExportExcel.excelWrite(map, list, excelName,request, response);
    }
}
